home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / chbar / progltx.sty < prev    next >
Encoding:
Text File  |  1991-04-09  |  26.6 KB  |  760 lines

  1. % This is PROGLTX.DOC               as of 25 May 90
  2. %---------------------------------------------------------
  3. % (c) 1989,1990 by J.Schrod. copy conditions see below
  4.  
  5. %
  6. % Macro package for the documentation of programs
  7. % LaTeX style option
  8. % MAKEPROG is needed
  9. %
  10.  
  11. %
  12. % DATE       PERSON  REMARK
  13. % 89-11-18 js       repaired the handling of `|' (verbatim and \index).
  14. % 89-10-05 js       first version (for TeX89)
  15. %
  16.  
  17. % author's current address:
  18. %
  19. %    Detig$\,\cdot\,$Schrod \TeX{}sys
  20. %    Joachim Schrod
  21. %    Kranichweg 1
  22. %
  23. %    D-6074 R\"odermark-Urberach
  24. %    FR Germany
  25. %
  26. %    Tel. (+6074) 1617
  27. %    Bitnet: XITIJSCH@DDATHD21
  28.  
  29.  
  30.  
  31. % documented with itself...
  32. %%%%
  33. %%%%
  34. %%%% These TeX macros were documented with the documentation system
  35. %%%% MAKEPROG and automatically converted to the current form.
  36. %%%% If you have MAKEPROG available you may transform it back to
  37. %%%% the original input: Remove every occurence of three percents
  38. %%%% and one optional blank from the beginning of a line and remove
  39. %%%% every line which starts with four percents.  The following lex
  40. %%%% program will do this:
  41. %%%%
  42. %%%%    %%
  43. %%%%
  44. %%%%    ^%%%\ ?   ;
  45. %%%%    ^%%%%.*\n ;
  46. %%%%
  47. %%%% MAKEPROG may be obtained over the net from the Bitnet-Listserver
  48. %%%% LISTSERV@DHDURZ1 (filelist WEBWARE), from tuglib@science.utah.edu,
  49. %%%% or via ftp from june.cs.washington.edu.
  50. %%%%
  51. %%%%
  52. %%% \documentstyle[progltx]{article}
  53.  
  54.  
  55. %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  56. %%% %
  57. %%% % local macros
  58. %%% %
  59.  
  60. %%% \let\mc=\small           % for names like GNU
  61.  
  62. %%% \def\WEB{{\tt WEB\/}}
  63. %%% \def\GNU{{\mc GNU}}
  64.  
  65. %%% %
  66. %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  67.  
  68.  
  69. %%% \begin{document}
  70.  
  71.  
  72. %%% \title{
  73. %%%    Documenting programs in a \WEB{} style\\
  74. %%%    The {\tt progltx\/} style option
  75. %%%    }
  76. %%% \author{\sc Joachim Schrod}
  77.  
  78. %%% \maketitle
  79.  
  80.  
  81. %%% \chap Introduction.
  82.  
  83. %%% \WEB{} systems allow the documentation of programs by supporting the
  84. %%% separation in program fragments which can be collected and rearranged
  85. %%% afterwards.  This allows {\it top-down\/} programming as well as the
  86. %%% {\it bottom-up\/} design of programs.  Each program fragment can be
  87. %%% documented, usually with \TeX{}\@.  A disadvantadge is that \WEB{}
  88. %%% actually exists only for a few programming languages (Pascal, C,
  89. %%% Modula-2).  Besides, building up \WEB{} systems for ``exotic''
  90. %%% programming languages like \TeX{} is very difficult.
  91.  
  92. %%% This macro package was built to allow good documentation for programs
  93. %%% in languages for which \WEB{} doesn't exist.  It separates a program
  94. %%% text in sections that can be documented.  All sections, collected
  95. %%% sequentially, will result in the complete program.  In every section
  96. %%% begin and end of the program part are marked with |\beginprog| and
  97. %%% |\endprog|, this program part will be formatted as it is input
  98. %%% (``verbatim'').
  99.  
  100. %%% Originally these macros were written for the usage with Plain \TeX{}
  101. %%% resp.\ on top of the \WEB{} macro package |webmac.tex|. But often the
  102. %%% requirement has been told to me that a \LaTeX{} version would be
  103. %%% useful, too---well, here it is. But even with \LaTeX{} I have decided
  104. %%% that still |\beginprog| and |\endprog| must be used for the markup of
  105. %%% the program parts, not |\begin{prog}| or |\end{prog}| which would be
  106. %%% more ``\LaTeX{}-like.'' The reason behind this is that I didn't want
  107. %%% to maintain two versions of the {\mc MAKEPROG\/} processor---but {\mc
  108. %%% MAKEPROG\/} wants to see the non-\LaTeX{}-like macros. But everybody
  109. %%% is encouraged to change it by themselves (it is {\it very\/} easy).
  110.  
  111. %%% The user of these macros may use the usual sectioning macros of
  112. %%% \LaTeX{} for structuring his documentation. Additionally we provide a
  113. %%% |progdoc|-compatible (i.e.\ \WEB{}-like) markup with the two macros
  114. %%% |\chap| and |\sect|.
  115.  
  116. %%% In the documentation part of a section text pieces, e.g.\ names of
  117. %%% variables, can be inserted verbatim to demonstrate the connection to
  118. %%% the program text.  These parts are included in vertical bars
  119. %%% (`{\tt\vbar}') This makes this style option extremely useful if your
  120. %%% identifiers (or your file names) include characters which would be
  121. %%% special characters for \TeX{} otherwise.  (One example of these
  122. %%% program languages is \TeX{} itself, but just enclose the macro names
  123. %%% in vertical bars and {\tt \vbar|\relax|\vbar}.)
  124.  
  125. %%% The macros |\makevertother| and |\makevertactive| are available to
  126. %%% activate and deactivate the special behaviour of the vertical bar but
  127. %%% these macros should be needed seldom because the usual cases as the
  128. %%% usage within |verbatim| and |tabular| environments or |\index| macros
  129. %%% etc.\ are handled.
  130.  
  131. %%% If a vertical bar must be used in the original fashion you can use two
  132. %%% command sequences: |\origvert| holds the meaning of the vertical bar
  133. %%% at the time this macro file was read in and |\vbar| is the character
  134. %%% with the {\mc ASCII\/} code of the vertical bar (i.e.~|"EC|) in the
  135. %%% current font.
  136.  
  137. %%% The new notion of |\verb| must not be used within parameters of
  138. %%% macros, e.g.\ in the argument of |\section| etc.---it will result in
  139. %%% an error message by \TeX{}\@.  Furthermore within the preamble of a
  140. %%% |tabular|, an |array| environment, or the |\multicolumn| command the
  141. %%% vertical bar has the same meaning as before.  (That means within
  142. %%% |@{|\ldots|}| it is an ordinary character and otherwise it specifies a
  143. %%% vertical rule between the columns.
  144.  
  145. %%% This macro package does not offer the automatic creation of an index
  146. %%% because it is not known which syntactical tokens the language has that
  147. %%% should be mentioned in an index. But of course all \LaTeX{} stuff like
  148. %%% |\index|, |\tableofcontents|, etc.\ may be used.
  149.  
  150.  
  151. %%% \sect This program is free software; you can redistribute it and/or
  152. %%% modify it under the terms of the \GNU{} General Public License as
  153. %%% published by the Free Software Foundation; either version~1, or (at your
  154. %%% option) any later version.
  155.  
  156. %%% This program is distributed in the hope that it will be useful, but
  157. %%% {\bf without any warranty\/}; without even the implied warranty of
  158. %%% {\bf merchantability\/} or {\bf fitness for a particular purpose}.  See
  159. %%% the \GNU{} General Public License for more details.
  160.  
  161. %%% You should have received a copy of the \GNU{} General Public License
  162. %%% along with this program; if not, write to the Free Software Foundation,
  163. %%% Inc., 675~Mass Ave, Cambridge, MA~02139, USA.
  164.  
  165.  
  166. %%% \sect We have to realize three parts:  (1)~the formatting of rather
  167. %%% small verbatim texts in a line, (2)~the formatting of larger parts of
  168. %%% program and (3)~the document structuring elements for the separation
  169. %%% of the sections.
  170.  
  171. %%% \begin{sloppypar}
  172. %%% Before we start we declare some shorthands for category codes. By
  173. %%% declaring the underscore~`(|_|)' as a letter we can use it in our
  174. %%% macros names. (I agree with D.~Knuth that
  175. %%% |\identifier_several_words_long| is more readable than
  176. %%% |\IdentifierSeveralWordsLong| and in every case better than
  177. %%% |\p@@@s|.) But as we have to restore the category codes at the end
  178. %%% of this macro file we store its former value in the control
  179. %%% sequence |\uscode|. This method is better than the usage of a
  180. %%% group because not all macros have to be defined global this way.
  181. %%% \end{sloppypar}
  182.  
  183. %%% \beginprog
  184. \chardef\escape=0
  185. \chardef\open=1
  186. \chardef\close=2
  187. \chardef\letter=11
  188. \chardef\other=12
  189. %\chardef\active=13         % is defined in Plain already
  190.  
  191. \chardef\uscode=\catcode`\_
  192.  
  193. \catcode`\_=\letter
  194. %%% \endprog
  195.  
  196.  
  197.  
  198.  
  199. %%% \chap Local Verbatim Formatting.
  200.  
  201. %%% The main point of every verbatim formatting is the switching of the
  202. %%% character codes of all characters that have a special \TeX{} meaning.
  203. %%% This can be done with the control sequence |\dospecials| that applies
  204. %%% the control sequence |\do| to all special characters.  Additionally,
  205. %%% every line is regarded as a paragraph without indentation.  Between
  206. %%% two paragraphs, i.e.\ between two lines, no extra space is set.
  207. %%% Finally all blanks and tabular characters shall be obeyed and the
  208. %%% inter word space after sentence terminators shall not be enlarged.
  209. %%% The activation of the tabular characters with |\obeytabs| is
  210. %%% equivalent to |\obeyspaces| in {\tt plain.tex}.
  211.  
  212. %%% \begin{sl}
  213. %%% As a matter of fact, I would like to use the character set with the
  214. %%% extended {\mc ASCII} (like in\/ \WEB{}) for setting the verbatim texts
  215. %%% in monospace. But then I must code many\/ |\@getfont|'s\,\dots
  216. %%% \end{sl}
  217.  
  218. %%% \beginprog
  219. %\font\tentex=cmtex10        % typewriter extended ASCII 10pt
  220. %\let\ttex=\tentex        % only with base size 10pt
  221. \def\ttex{\tt}            % as a substitute
  222.  
  223. \def\setup_verbatim{%
  224.    \def\do##1{\catcode`##1\other}\dospecials
  225.    \parskip\z@skip \parindent\z@
  226.    \catcode`\`\active \@noligs
  227.    \obeylines \@vobeyspaces \obeytabs \frenchspacing
  228.    \ttex
  229.    }
  230.  
  231. \let\tab=\space
  232. \begingroup
  233.    \catcode`\^^I=\active%    % Attention: no tabs!
  234.    \gdef\obeytabs{\catcode`\^^I=\active\def^^I{\tab}}
  235.    \global\let^^I=\tab%    % if an active tab appears in a \write
  236. \endgroup
  237. %%% \endprog
  238.  
  239.  
  240. %%% \sect After having saved the old meaning of `{\tt\vbar}' in
  241. %%% |\origvert| and after declaring |\vbar| as a synonym for the character
  242. %%% that has the code of a vertical bar in the actual font, the vertical
  243. %%% bar can be made active.  Then we call |\setup_verbatim|.  But the
  244. %%% newline characters shall not be processed, they shall be regarded like
  245. %%% blank space.  This can be reached by defining |\par| as |\space|.
  246.  
  247. %%% The next vertical bar in the input closes the group which becomes an
  248. %%% (unbreakable) |\hbox| then.  The old meanings of the special
  249. %%% characters and of the vertical bar are restored and \TeX{} is in
  250. %%% normal (horizontal) mode again.
  251.  
  252. %%% \beginprog
  253. \let\origvert=|
  254. \chardef\vbar=`\|
  255.  
  256. \def\makebaractive{\catcode`\|\active}
  257. \def\makebarother{\catcode`\|\other}
  258. \makebaractive
  259.  
  260. \def|{%
  261.    \leavevmode
  262.    \hbox\bgroup
  263.       \let\par\space \setup_verbatim
  264.       \let|\egroup
  265.    }
  266. %%% \endprog
  267.  
  268.  
  269. %%% \sect A problem with this definition of the vertical bar is that
  270. %%% the bar is not a normal character any more but there exists situations
  271. %%% where the \LaTeX{} macros assumes this:
  272. %%% %
  273. %%% \begin{itemize}
  274.  
  275. %%% \item In a |verbatim| environment a vertical bar must be typeset if it
  276. %%% occurs in the input.
  277.  
  278. %%% \item In a |tabular| or an |array| environment a vertical bar is used
  279. %%% to denote rules between columns in the table. These environments must
  280. %%% be started with a parameter which is a ``preamble,'' the same preamble
  281. %%% construction is used to specify the format of multi-column entries.
  282.  
  283. %%% \item In an output of an index entry the vertical bar must not result
  284. %%% in an error message. Usually index entries are typeset in a seperate
  285. %%% \TeX{} run where |idverb| is not used as a style option and the
  286. %%% vertical bar is therefore useful. This is no problem in section
  287. %%% headings or captions etc. Because they take their argument as a
  288. %%% parameter in every case the vertical bar can never be used there. But
  289. %%% |\origvert| resp.\ |\vbar| may be used there.
  290.  
  291. %%% \end{itemize}
  292. %%% %
  293. %%% In the next sections we handle each of these problems.
  294.  
  295.  
  296. %%% \sect Before we start a |verbatim| environment we just redefine the
  297. %%% vertical bar as an ordinary character. Because this is within the
  298. %%% environment grouping the end of the environment will reestablish the
  299. %%% special meaning.
  300.  
  301. %%% \beginprog
  302. \let\@@verbatim=\@verbatim
  303. \def\@verbatim{%
  304.    \makebarother
  305.    \@@verbatim
  306.    }
  307. %%% \endprog
  308.  
  309.  
  310. %%% \sect Special care is needed in the |tabular| and the |array|
  311. %%% environment.  Both environments are begun by one macro (|\@tabarray|),
  312. %%% we redefine it so that the bar can be used in the preamble
  313. %%% specification.    The same problem occurs in |\multicolumn|, it is
  314. %%% solved the same way.  After the preamble construction (with
  315. %%% |\@mkpream|) the special meaning of the bar can be switched on
  316. %%% again---this allows the usage of the new meaning in the body of a
  317. %%% table.
  318.  
  319. %%% Of course this mean that the ``verbatim identifier'' facility can
  320. %%% not be used within a preamble of a table. Furthermore it can not
  321. %%% be used within the |\multicolumn| statement, neither in the
  322. %%% preamble part (the second parameter) nor within the text part (the
  323. %%% third parameter).
  324.  
  325. %%% \beginprog
  326. \let\@@tabarray=\@tabarray
  327. \def\@tabarray{%
  328.    \makebarother
  329.    \@@tabarray
  330.    }
  331.  
  332. \def\multicolumn#1{%
  333.    \multispan{#1}%
  334.    \begingroup
  335.       \makebarother
  336.       \restof_multicolumn
  337.    }
  338. \def\restof_multicolumn#1#2{%
  339.       \@mkpream{#1}%
  340.       \def\@sharp{#2}%
  341.       \let\protect\relax
  342.       \let\@startpbox\@@startpbox  \let\@endpbox\@@endpbox
  343.       \@arstrut \@preamble
  344.    \endgroup
  345.    \ignorespaces
  346.    }
  347.  
  348. \let\@@mkpream=\@mkpream
  349. \def\@mkpream#1{%
  350.    \@@mkpream{#1}%
  351.    \makebaractive
  352.    }
  353. %%% \endprog
  354.  
  355.  
  356. %%% \sect Before an index entry is scanned almost all special characters
  357. %%% are transformed into ordinary characters. The only exceptions are the
  358. %%% opening and the closing brace because they are needed to delimit the
  359. %%% argument. This transformation is done with |\@sanitize|, this macro
  360. %%% must be called within a group. We just append the transformation of
  361. %%% the vertical bar.
  362.  
  363. %%% \beginprog
  364. \begingroup
  365.    \def\@makeother{\noexpand\@makeother\noexpand}
  366.    \xdef\@sanitize{\@sanitize\@makeother\|}
  367. \endgroup
  368. %%% \endprog
  369.  
  370.  
  371.  
  372.  
  373. %%% \chap Fragments in Verbatim.
  374.  
  375. %%% We need macros to format the program fragments without any
  376. %%% linebreaking.  Such a text area shall start with the macro
  377. %%% |\beginprog| and end with |\endprog|, i.e.\ as a kind of a
  378. %%% |prog|-environment.  The macro |\endprog| must stand at the very
  379. %%% beginning of a line and must be followed by white space (blank, tab or
  380. %%% newline character).  After |\beginprog| as well as after
  381. %%% |\endprog| the rest of the line is ignored.
  382.  
  383. %%% Two demands must be regarded:  There should be no length restrictions
  384. %%% for the processed text, and the tabular characters should be expanded
  385. %%% so that this macro works on PC's and on VAXes etc., too.
  386.  
  387.  
  388. %%% \sect The implementation method is quite simple:  We read the next
  389. %%% line, test, wether the end is reached (by comparing with the end line)
  390. %%% and otherwise set the line actually read.  Every character is
  391. %%% inspected and tabular characters are expanded.
  392.  
  393. %%% The verbatim text is started with |\begin_verbatim| which will be
  394. %%% either called by |\beginprog| or by |\beginverbatim|. These macros
  395. %%% will also define the contents of the end line.
  396.  
  397. %%% Whether a line is set or whether the end of the processed area is
  398. %%% reached is indicated by the switch |\if@print|.  At the beginning of
  399. %%% the |\begin_verbatim| macro most settings are done with
  400. %%% |\setup_verbatim| (the vertical bar must be handled separately)
  401. %%% and the rest of the line is ignored.  As everything is done within
  402. %%% a group, the end of the verbatim text can be processed by simply
  403. %%% closing this group.
  404.  
  405. %%% For the user it looks as if |\endprog| or |\endverbatim|
  406. %%% terminates the processing, but it just serves for the
  407. %%% identification of the end, the true processing is done with the
  408. %%% internal macro |\end_verbatim|.
  409.  
  410. %%% \beginprog
  411. \newif\if@print
  412.  
  413. \def\begin_verbatim{%
  414.    \endgraf
  415.    \bigbreak
  416.    \begingroup
  417.       \setup_verbatim \makebarother
  418.       \@printtrue
  419.       \ignore_rest_line
  420.    }
  421. \let\end_verbatim=\endgroup        % internal command !
  422. %%% \endprog
  423.  
  424.  
  425. %%% \sect {\sloppy 
  426. %%%  The first line is ignored, all the other lines are identified with
  427. %%% |\set_next_line| and processed with |\do_set|.  This separation in
  428. %%% identification and processing allows that the line end character is
  429. %%% active in the definition only for a short time.
  430. %%%  \par}
  431.  
  432. %%% When a line is to be formatted, we first check with |\check_print|
  433. %%% wether it contains the end line, otherwise it is printed with
  434. %%% |\print_char|.    The printing must be done for every character
  435. %%% individually because we want to check for tabular characters; the
  436. %%% exact algorithm is described below.  Here we just have to note that
  437. %%% |\print_char| is used with two parameters of which the second one is
  438. %%% finished with the token |\end_line|.  The first parameter is the first
  439. %%% character of the line, the second parameter is the rest of the line.
  440. %%% If the line is empty, the argument of |\do_set| is empty, too; so the
  441. %%% activation of |\print_char| must be finished with two |\end_line|.
  442. %%% Then the first |\end_line| is the first argument for |\print_char| and
  443. %%% the second argument is empty.  But if the line did contain something,
  444. %%% the second |\end_line| is evaluated, for this case it is defined as
  445. %%% |\relax|.
  446.  
  447. %%% At last we call |\set_next_line| again to format the next line.  If
  448. %%% the end is reached, i.e.\ if the sample line was found,
  449. %%% |\set_next_line| will be redefined as |\relax|.  This can be done
  450. %%% because the original meaning is restored while closing the group
  451. %%% with |\end_verbatim|.
  452.  
  453. %%% \beginprog
  454. \begingroup
  455.    \obeylines%    % ^^M is active! ==> every line must end with %
  456.    \gdef\ignore_rest_line#1^^M{\set_next_line}%
  457.    \gdef\set_next_line#1^^M{\do_set{#1}}%
  458. \endgroup
  459.  
  460. \def\do_set#1{%
  461.    \endgraf
  462.    \check_print{#1}%
  463.    \if@print  \indent \print_char#1\end_line\end_line
  464.    \else  \let\set_next_line\end_verbatim
  465.    \fi
  466.    \set_next_line
  467.    }
  468. \let\end_line=\relax
  469. %%% \endprog
  470.  
  471.  
  472. %%% \sect {\sloppy
  473. %%%  Before we look at the problem of formatting a line, we declare
  474. %%% |\check_print| that checks the end of the verbatim mode.  We have to
  475. %%% do two things:    we must split everything in front of the first blank
  476. %%% or tabular character and compare for identity with |\endprog|.    The
  477. %%% splitting is easy because the line which is our first argument
  478. %%% contains blanks and tabulators as active characters.  First we call
  479. %%% |\cut_at_tab| that demands a tabular character as separator for its
  480. %%% two pramenters so that everything in the line in front of the first
  481. %%% tabulator is part of the first parameter.  If there is no tabular
  482. %%% character in the line, we append one so that the second parameter is
  483. %%% empty.    The same trick is used to separate the part in front of the
  484. %%% first blank character from the resulting first part.
  485. %%%  \par}
  486.  
  487. %%% The check is done with |\do_check|.  We use a separate macro here so
  488. %%% that we can indent it (in the following definition blanks are active!)
  489.  
  490. %%% \beginprog
  491. \begingroup
  492. \obeyspaces\obeytabs
  493. \gdef\check_print#1{\cut_at_tab#1^^I\end_line}
  494. \gdef\cut_at_tab#1^^I#2\end_line{\check_first_part#1 \end_line}% blank !
  495. \gdef\check_first_part#1 #2\end_line{\do_check{#1}}
  496. \endgroup
  497. %%% \endprog
  498.  
  499.  
  500. %%% \sect
  501. %%% \begin{sloppypar}
  502. %%% |\do_check| compares the line with a sample line that is
  503. %%% available in |\end_verbatim_line|.  This macro will be defined later.
  504. %%% \end{sloppypar}
  505.  
  506. %%% \beginprog
  507. \def\do_check#1{%
  508.    \def\@line{#1}%
  509.    \ifx \@line\end_verbatim_line  \@printfalse
  510.    \fi
  511.    }
  512. %%% \endprog
  513.  
  514.  
  515. %%% \sect Now we can set a line:  we start with the first character,
  516. %%% followed by the rest of the line.  Each character is counted in
  517. %%% |\char_count|.    At the beginning of a line |\char_count| is~0, this
  518. %%% is reset at the end of the line.
  519.  
  520. %%% \beginprog
  521. \newcount\char_count  \char_count\z@
  522.  
  523. \def\print_char#1#2\end_line{%
  524.    \print_first_char{#1}%
  525.    \print_rest_of_line{#2}%
  526.    }
  527. %%% \endprog
  528.  
  529.  
  530. %%% \sect For each character that is set |\char_count| is incremented.
  531. %%% If a character is a tabulator, we set with |\print_tab| the fitting
  532. %%% amount of blank characters, otherwise the character itself.  We must
  533. %%% compare the character that is stored in |\@char| with a macro of which
  534. %%% the ``first-level'' expansion is an active tabulator.  For this case
  535. %%% we declare |\@tab|.
  536.  
  537. %%% \beginprog
  538. {\obeytabs\gdef\@tab{^^I}}
  539.  
  540. \def\print_first_char#1{%
  541.    \def\@char{#1}%
  542.    \advance \char_count\@ne
  543.    \ifx \@char\@tab  \print_tab
  544.    \else  \@char
  545.    \fi
  546.    }
  547. %%% \endprog
  548.  
  549.  
  550. %%% \sect If we want to fill the line with blank spaces up to the next
  551. %%% column with a number that can be divided by~8, we must be able to
  552. %%% compute the column number modulo~8, but \TeX{} has no modulo operator.
  553. %%% So we define the macro |\mod_viii| that computes its argument modulo~8
  554. %%% and returns the result in the counter |\count_mod_viii|.  For the
  555. %%% computation we need the temporary counter |\count@|.
  556.  
  557. %%% \beginprog
  558. \newcount\count_mod_viii
  559. \def\mod_viii#1{%
  560.    \count@ #1\relax  \count_mod_viii\count@
  561.    \divide \count@ 8\relax
  562.    \multiply \count@ 8\relax
  563.    \advance \count_mod_viii -\count@
  564.    }
  565. %%% \endprog
  566.  
  567.  
  568. %%% \sect Now we can declare |\print_tab|.    We must remember that
  569. %%% |\char_count| was incremented already, if we set only one blank
  570. %%% character the counter keeps untouched.
  571.  
  572. %%% \beginprog
  573. \def\print_tab{%
  574.    \loop  \space \mod_viii\char_count
  575.       \ifnum \count_mod_viii>\z@
  576.      \advance \char_count\@ne
  577.    \repeat
  578.    }
  579. %%% \endprog
  580.  
  581.  
  582. %%% \sect If the rest of the line is empty, we are ready.  |\char_count|
  583. %%% is reset to~0 for the next line.
  584.  
  585. %%% Inside the |\else| part of |\ifx| |\print_char| should not be used
  586. %%% directly because this costs too much storage of \TeX{}\@.  Instead we
  587. %%% set a control sequence |\next| that is processed afterwards, depending
  588. %%% on the result of the comparison.  (This tail recursion will be
  589. %%% discovered by \TeX{} and handled appropriately.) If there is still
  590. %%% something to set, we use |\print_char| again, otherwise a
  591. %%% syntactically similar macro that expands to |\relax|.
  592.  
  593. %%% \beginprog
  594. \def\print_rest_of_line#1{%
  595.    \def\@line{#1}%
  596.    \ifx \@line\empty  \char_count\z@
  597.       \def\next##1\end_line{\relax}%
  598.    \else  \let\next\print_char
  599.    \fi
  600.    \next#1\end_line
  601.    }
  602. %%% \endprog
  603.  
  604.  
  605. %%% \sect {\sloppy
  606. %%% Now we are ready to define the two ``user accessible'' macros
  607. %%% |\beginprog| and |\beginverbatim|. They must define the prototyp end
  608. %%% line |\end_verbatim_line| which will be compared against every line
  609. %%% in the verbatim text. During the definition of
  610. %%% |\end_verbatim_line| it must be cared for that the escape character~`|\|'
  611. %%% is a printable character:  A comparison with |\ifx| demands identical
  612. %%% category codes.  As a temporary escape character we use the slash.
  613. %%% \par}
  614.  
  615. %%% \beginprog
  616. {\catcode`\/=\escape        % / is temporary escape char 
  617.    \catcode`\\=\other
  618.    /gdef/beginprog{%
  619.       /gdef/end_verbatim_line{\endprog}%
  620.       /begin_verbatim
  621.       }
  622.    /gdef/beginverbatim{%
  623.       /gdef/end_verbatim_line{\endverbatim}%
  624.       /begin_verbatim
  625.       }
  626. }                 % here \endgroup can't be used
  627. %%% \endprog
  628.  
  629.  
  630.  
  631.  
  632. %%% \chap Document Structuring.
  633.  
  634. %%% In addition to the normal \LaTeX{} structuring markups we will
  635. %%% provide a markup for a layout of the document that is like in
  636. %%% \WEB{}.  This can be done easily. All sections are numbered, the
  637. %%% number of the next section is stored in the counter |section|.    We
  638. %%% distinguish between main sections which start a group of sections
  639. %%% and between normal sections within a group.
  640.  
  641. %%% The main sections are started with the macro |\chap|. It has one
  642. %%% parameter, the title of the section group. This parameter must be
  643. %%% terminated by a dot.  We start a new page, typeset the title in
  644. %%% bold face and separate it from the section text with a |\medskip|.
  645. %%% This text, the documentation part of the section, is formatted
  646. %%% without paragraph indentation.
  647.  
  648. %%% If the \WEB{}-like macros are used every section number should be
  649. %%% output with a following dot. We want to establish this when we use the
  650. %%% |\chap| or the |\sect| macro the first time. Furthermore the new page
  651. %%% at the begin of a main section should not be started at the first
  652. %%% |\chap| because a title may precede it (and the title should not
  653. %%% be on a seperate page unless explicitely requested). Instead a
  654. %%% skip of (approximately) 2~pica should be set. To achieve
  655. %%% both goals a macro |\chap_intro| is defined that defines |\thesection|
  656. %%% appropriately, skips the 2~pica, and redefines itself to
  657. %%% |\newpage|---we then just have to call |\chap_intro| at the beginning
  658. %%% of |\chap|. The same applies to |\sect_intro|.
  659.  
  660. %%% \beginprog
  661. \newskip\pre_sect_skip    \pre_sect_skip=2pc plus 1pc minus 6pt
  662.  
  663. \def\chap_intro{%
  664.    \gdef\thesection{\arabic{section}.}%
  665.    \gdef\chap_intro{\newpage}%
  666.    \addvspace{\pre_sect_skip}%
  667.    }
  668.  
  669. \def\sect_intro{%
  670.    \gdef\thesection{\arabic{section}.}%
  671.    \global\let\sect_intro\relax
  672.    }
  673. %%% \endprog
  674.  
  675.  
  676. %%% \sect Now we will have a look at the {\it wonderful\/} internal
  677. %%% interface of \LaTeX{}\@. With ``wonderful'' I mean that I'm always
  678. %%% full of wonder why it was designed in this way. E.g., if anybody
  679. %%% can explain to me why the coding of the non-indentation of the first
  680. %%% line in the following paragraph was combined with the coding of
  681. %%% the skip which will come in front of the section---I will be thankful
  682. %%% for the rest of my life. Such different things should be kept
  683. %%% different, i.e., the suppression of the indentation should not be
  684. %%% hidden in the sign of a skip! The same comment applies to the combined
  685. %%% coding of the skip below the section heading resp.\ to the right
  686. %%% of a run-in heading.
  687.  
  688. %%% \begin{quote} \it
  689. %%% I want the following layout: no indentation in the following
  690. %%% paragraph\/ {\rm but no} space in front of the section heading.
  691. %%% How do I code a value of\/ $\sl -0 pt$?
  692. %%% \end{quote}
  693. %%% %
  694. %%% Well, a work-around is to use a value of $\rm -1\,sp$ because the
  695. %%% reader will not see this distance---but in my opinions this is no
  696. %%% good programming style. In this special case I have luck, too:
  697. %%% the skip is not set anyway, either it is discarded by the preceding
  698. %%% |\newpage| or it is not added by |\addvspace| because of the preceding
  699. %%% |\pre_sect_skip|.
  700.  
  701. %%% \beginprog
  702. \def\chap#1.{%
  703.    \chap_intro
  704.    \@startsection{section}{1}%
  705.       {\z@}%
  706.       {\m@ne sp}%
  707.       {\medskipamount}%
  708.       {\normalsize\bf}%
  709.       {#1.}%
  710.    }
  711. %%% \endprog
  712.  
  713.  
  714. %%% \sect Normal sections are started with |\sect|.  This macro has no
  715. %%% parameter.  Between two paragraphs we skip |\pre_sect_skip|.
  716. %%% Between the section number and the text one quad of space is set.
  717. %%% We have to take care for empty documentation parts where the
  718. %%% program part (i.e.\ |\beginprog|) will follow immediately. Then
  719. %%% the program part should begin on a new line and not behind the
  720. %%% section number. So we provide |\null| as an empty documentation
  721. %%% part in every case.
  722.  
  723. %%% Now again the design of |\@startsection| comes in hand: \LaTeX{}
  724. %%% always leaves a quad after the section number (by the way,
  725. %%% this is not mentioned in the documentation---you have to look
  726. %%% in the macros to figure this out). Because our section header
  727. %%% consists only of the number we have to code a value of $\rm
  728. %%% -0\,pt$\,\dots
  729.  
  730. %%% \begin{quote}
  731. %%% Again: {\it non-orthogonal design is bad design}.
  732. %%% \end{quote}
  733.  
  734. %%% \beginprog
  735. \def\sect{%
  736.    \sect_intro
  737.    \@startsection{section}{1}%
  738.       {\z@}%
  739.       {\pre_sect_skip}%
  740.       {\m@ne sp}%
  741.       {\normalsize\bf}%
  742.       {\null}%
  743.    }
  744. %%% \endprog
  745.  
  746.  
  747. %%% \sect We are finished and just have to restore the category code.
  748.  
  749. %%% \beginprog
  750. \catcode`\_=\uscode
  751.  
  752. \endinput
  753. %%% \endprog
  754.  
  755.  
  756.  
  757.  
  758.  
  759. %%% \end{document}
  760.